<?php $deleteImg = img("images/icons/cancel.png");?>
<?php $editImg = img("images/icons/pencil.png")?>

<div id="main_content"><?php if(isset($isLoggedIn) && $isLoggedIn==TRUE && $this->user_model->sessionUser($userid)):?>
<h1><?php echo anchor(base_url().'index.php/user/profile/userid/'.$userid, 'User Profile');?>
- <?php echo anchor(base_url().'index.php/user/settings/userid/'.$userid, 'User Settings');?></h1>
<?php else:?>
<h1>User Profile</h1>
<?php endif;?>
<h2>User Information</h2>
<table>
	<tr>
		<td>Username:</td>
		<td><?php echo $username;?></td>
	</tr>
	<tr>
		<td>OpenID:</td>
		<td><?php echo $openidURL;?></td>
	</tr>
	<tr>
		<td>Email:</td>
		<td><?php echo $email;?></td>
	</tr>
</table>
<table>
	<tr>
		<td colspan="0">
		<h2>User Articles</h2>
		</td>
	</tr>
	<?php if(count($userarticles)!=0):?>
	<tr>
		<th>Title</th>
		<th></th>
		<th>Category</th>
		<th>Date</th>
		<?php if(isset($isLoggedIn) && $isLoggedIn==TRUE && $isSessionUser==TRUE) : ?>
		<th>Edit</th>
		<th>Delete</th>
		<?php endif; ?>
	</tr>
	<?php foreach($userarticles as $article):?>
	<tr>
		<td><?php echo anchor(base_url().'index.php/articles/id/'.$article->articleID,$article->title);?></td>
		<td></td>
		<td><?php echo $this->articles_model->getCategoryName($article->categoryID);?>
		<td><?php echo $article->date;?></td>
		<?php if(isset($isLoggedIn) && $isLoggedIn==TRUE && $isSessionUser==TRUE) : ?>
		<td><?php echo anchor(base_url().'index.php/articles/edit/'.$article->articleID, $editImg); ?></td>
		<td><?php echo anchor(base_url().'index.php/articles/delete/'.$article->articleID, $deleteImg); ?></td>
		<?php endif; ?>
	
	</tr>
	<?php endforeach;?>
	<?php else:?>
	<tr>
		<td colspan="0">No articles written...</td>
	</tr>
	<?php endif;?>
	<tr>
		<td colspan="0">
		<h2>Bookmarked articles</h2>
		</td>
	</tr>
	<?php if(count($bookmarkedarticles)!=0):?>
	<tr>
		<th>Title</th>
		<th>Author</th>
		<th>Category</th>
		<th>Date</th>
		<?php if(isset($isLoggedIn) && $isLoggedIn==TRUE && $isSessionUser==TRUE) : ?>
		<th>Remove</th>
		<?php endif; ?>
	</tr>
	<?php foreach($bookmarkedarticles as $article):?>
	<tr>
		<td><?php echo anchor(base_url()."index.php/articles/id/$article->articleID", $article->title);?></td>
		<td><?php echo $this->user_model->getUsername($article->userID)?></td>
		<td><?php echo $this->articles_model->getCategoryName($article->categoryID);?>
		<td><?php echo $article->date;?></td>
		<?php if(isset($isLoggedIn) && $isLoggedIn==TRUE && $isSessionUser==TRUE) : ?>
		<td><?php echo anchor(base_url()."index.php/articles/unbookmarkArticle/authorid/$article->articleID/userid/$userid", $deleteImg);?></td>
		<?php endif; ?>
	
	</tr>
	<?php endforeach;?>
	<?php else: ?>
	<tr>
		<td colspan="0">No bookmarked articles...</td>
	</tr>
	<?php endif;?>
	<tr>
		<td colspan="0">
		<h2>Subscriptions</h2>
		</td>
	</tr>
	<?php if(count($subscriptions)!=0):?>
	<tr>
		<th>Author</th>
		<?php if(isset($isLoggedIn) && $isLoggedIn==TRUE && $isSessionUser==TRUE) : ?>
		<th>Remove</th>
		<?php endif; ?>
	</tr>
	<?php foreach($subscriptions as $subscription):?>
	<tr>
		<td><?php echo anchor(base_url()."index.php/user/profile/userid/$subscription->authorID", $this->user_model->getUsername($subscription->authorID));?></td>
		<?php if(isset($isLoggedIn) && $isLoggedIn==TRUE && $isSessionUser==TRUE) : ?>
		<td><?php echo anchor(base_url()."index.php/articles/unsubscribe/authorid/$subscription->authorID/userid/$userid", $deleteImg);?></td>
		<?php endif; ?>
	</tr>
	<?php endforeach;?>
	<?php else: ?>
	<tr>
		<td colspan="0">No subscriptions...</td>
	</tr>
	<?php endif;?>
	<?php //todo add code to generate which users the user is subscribing?>
</table>
</div>
